/*
 * @Author: Zhang Wei
 * @Date: 2022-04-17 19:48:23
 * @LastEditors: Zhang Wei
 * @LastEditTime: 2022-04-18 00:10:34
 * @FilePath: \02_tank\src\model\ModelAbstract.ts
 * @Word: There is nothing either good or bad, but thinking makes it so.
 * @Description:
 */

import config from '../config';

import { directionEnum } from './../enum/directionEnum';

export default abstract class ModelAbstract {
  abstract render(): void;
  abstract name: string;
  abstract getImg(): HTMLImageElement;

  protected direction: directionEnum = directionEnum.top;

  public width: number = config.module.width;
  public height: number = config.module.height;

  constructor(protected canvas: CanvasRenderingContext2D, public x: number, public y: number) {
    this.randomDirection();
  }

  // 随机产生一个方向
  protected randomDirection() {
    this.direction = Object.keys(directionEnum)[Math.floor(Math.random() * 4)] as directionEnum;
    // console.log(this.direction, 'this.direction');
  }

  // 绘制
  protected draw() {
    let img = this.getImg();
    this.canvas.drawImage(img, this.x, this.y, config.module.width, config.module.height);
    return this;
  }
}
